# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/7/16 11:29
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/rpc_dao.git
# @File    : car_insurance.py
# @Software: PyCharm
# @Version: 2.7.5
from idl_output.ttypes import CarInsuranceInfo
from db import car_insurance
from utils import my_decorator


@my_decorator.handle_exception()
def add_car_insurance_info(info):
	thrift_data = CarInsuranceInfo(info)
	car_insurance.add_car_insurance_info(thrift_data.LicenseNo, thrift_data.FrameNo, thrift_data.EngineNo,
	                              thrift_data.BiOrderNumber, thrift_data.CiOrderNumber, thrift_data.BiDate,
	                              thrift_data.CiDate, thrift_data.InsuranceUnit, thrift_data.InsuranceContent)


@my_decorator.handle_exception()
def get_car_insurance_info(licenseNo, frameNo, engineNo):
	orm_data = car_insurance.get_car_insurance_info(licenseNo, frameNo, engineNo)
	if not orm_data:
		return None

	thrift_data = CarInsuranceInfo(BiDate=orm_data.biDate, CiDate=orm_data.ciDate,
	                               InsuranceUnit=orm_data.InsuranceUnit,
	                               InsuranceContent=orm_data.InsuranceContent)
	return thrift_data